<!doctype html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=0, width=device-width"/>
	<title>api</title>
	<link rel="stylesheet" type="text/css" href="../css/api.css" />
	<link rel="stylesheet" type="text/css" href="../css/common.css" />
	<link rel="stylesheet" type="text/css" href="../css/address.css" />	
</head>

<body >
<script id="address-template" type="text/x-dot-template">
{{ for(var i=0; i< it.length; i++) { }}
	<article class="yrd_col clearfix">
            <p>{{=it[i].shouhuoren}}&nbsp;&nbsp;{{=it[i].sheng}}&nbsp;&nbsp;{{=it[i].shi}}&nbsp;&nbsp;
                {{=it[i].xian}}&nbsp;&nbsp;
                {{=it[i].jiedao}}&nbsp;&nbsp;&nbsp;&nbsp;{{=it[i].mobile}}&nbsp;&nbsp;{{=it[i].youbian}}</p>
            <br>
            

            <a class="edite_address" id="editeAddress" onclick="openWin('addAddress',{{=it[i].id}})">编辑</a>
            <a class="del_address" onclick="del_address({{=it[i].id}})">删除</a>
            {{if(it[i].default=='Y'){}}
            <a style="color:green">默认地址</a>           
            {{}}}
    </article>
{{}}}
</script>
<script id="add-template" type="text/x-dot-template">
<a onclick="openWin('addAddress')" id="addAddress" class="greyBtn w48">添加收货地址</a>
</script>
 <div  class="main address_manage">
	<article id='add-content'>
		
	</article>
	<div id='address-content'>
	
	</div>
	
                    
 </div>
</body>
	<script type="text/javascript" src="../script/zepto.min.js"></script>
	<script type="text/javascript" src="../script/api.js"></script>		
	<script type="text/javascript" src="../script/doT.min.js"></script>
	<script type="text/javascript" src="../script/common.js"></script>
	<script>
		var uid='';
		apiready = function(){
		api.addEventListener({
	        name:'addressreload'
        },function(ret,err){
        	//coding...
        	if(ret.value.reload){
        		addressList(uid)
        	}
        });
		uid =api.pageParam.uid;
		addressList(uid)
		
						var add =$api.byId('add-content');
				        var t = $api.byId('add-template').text;
				        var tempFn = doT.template(t);
				       $api.html(add,tempFn(uid));
				       
			
			
		}
		function del_address(id){
		
			api.confirm({
			    title: '确定保存',
			    msg: '亲，是否确定删除？',
			    buttons: ['确定', '取消']
			}, function(ret, err){
			    var index = ret.buttonIndex;
			    if(index==1){
			    	
			    	api.ajax({
						url: 'http://wap.jqmao.cn/delAddress/?id='+id,
				        method: 'get',
						},function(ret, err){
							if(ret){
								if(ret['code']=='1'){
								
									addressList(uid)
								}else{
									toast('删除失败')
								}
							}else{
								toast('网络出错')
							}
						})
			    }
			});
		
			
		}
		
		function addressList(uid){
             
				api.ajax({
		        url: 'http://wap.jqmao.cn/getAddressList/?uid='+uid,
		        method: 'get',
		       
    			}, function (ret, err) {
    					var a =$api.byId('address-content');
				        var tpl = $api.byId('address-template').text;
				        var tempFn = doT.template(tpl);
    				if(ret){
    				//alert(JSON.stringify(ret))
    					
				       $api.html(a,tempFn(ret));
    					
    				}else{
    					$api.html(a,tempFn(''));
    				}
    				
    		})
		}
	</script>

</html>